package com.xucy.springboot.activemq;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

import javax.jms.ConnectionFactory;

/**
 * @Author xucy
 * @Date 2019-07-05 09:54
 * @Description
 **/

@Configuration
public class ActiveMqConfig {

    /**
     * queue模式下的listenerContainer
     *
     * @Author xucy
     * @Date 10:00 2019-07-05
     * @param
     * @return
     */
    @Bean
    public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ConnectionFactory activeMQConnectionFactory){

        DefaultJmsListenerContainerFactory bean =new DefaultJmsListenerContainerFactory();
        bean.setConnectionFactory(activeMQConnectionFactory);
        return bean;
    }

    /**
     * topic模式下的listenerContainer
     *
     * @Author xucy
     * @Date 10:00 2019-07-05
     * @param
     * @return
     */
    @Bean
    public JmsListenerContainerFactory<?> jmsListenerContainerTopic(ConnectionFactory connectionFactory){
        DefaultJmsListenerContainerFactory bean =new DefaultJmsListenerContainerFactory();
        bean.setPubSubDomain(true);
        bean.setConnectionFactory(connectionFactory);
        return bean;
    }
}
